/**
 * 添加或者修改页面
 */
var HxOrderOutInfoDlg = {
    data: {
        customerId: "",
        customerName: "",
        orderState: "",
        peisongTime: "",
        orderOutNumber: "",
        orderType: "",
        setUnitId: "",
        setUnit: "",
        getWarehouseId: "",
        getWarehouse: "",
        getUnitId: "",
        getUnit: "",
        goodsNum: "",
        outNum: "",
        zNum: "",
        lNum: "",
        putVolume: "",
        createUserName: "",
        submitUserName: "",
        revokeUserName: "",
        createTime: "",
        submitTime: "",
        revokeTime: "",
        completeTime: "",
        notes: "",
        associationOrder: "",
        associationOrderType: "",
        goodsId: "",
        goodsName: "",
        goodsNumber: "",
        goodsPcode69: "",
        goodsSpecs: "",
        unit: "",
        rate: "",
        psNum: "",
        v1: "",
        v2: "",
        v3: "",
        v4: "",
        v5: "",
        v6: "",
        deptId: "",
        deliverId: ""
    }
};

layui.use(['form', 'admin', 'ax','laydate'], function () {
    var $ = layui.jquery;
    var $ax = layui.ax;
    var form = layui.form;
    var admin = layui.admin;
    var laydate = layui.laydate;

    laydate.render({
        elem:'#updateTime'
        ,type:'datetime'
    });

    //让当前iframe弹层高度适应
    admin.iframeAuto();


    //表单提交事件
    form.on('submit(btnSubmit)', function (data) {
        var index;
        $.ajax({
            url: Feng.ctxPath + "/hxBasicGoods/checksgoods",  // 请求的URL
            cache: false,  // 不缓存此请求
            dataType: "json",  // 期望的响应数据类型
            data: data.field,  // 发送到服务器的数据
            beforeSend: function() {
                // 请求之前显示加载中的提示
                index = layer.msg('确认中。。。请耐心等待', {
                    icon: 16,          // 显示加载的图标
                    shade: [0.2, '#000'], // 背景遮罩，0.2透明度的黑色
                    time: false        // 不自动关闭
                });
            },
            success: function(data) {
                // 关闭加载中的提示
                parent.layer.close(index);
                // 获取当前窗口的索引
                var Indexs = parent.layer.getFrameIndex(window.name);
                if (data.success) {
                    // 如果请求成功
                    parent.submit = 1;
                    console.log(data.message);
                    // 显示成功提示弹窗
                    if (Array.isArray(data.message) && data.message.length > 0) {
                        layer.open({
                            title: '成功提示',
                            content: data.message+"商品换算率不一致！请检查",
                            btn: ['确定'],
                            yes: function (index, layero) {
                                layer.close(index); //关闭当前弹窗
                                parent.layer.close(Indexs);
                            }
                        });
                    } else{
                        layer.open({
                            title: '成功提示',
                            content:"无不一致商品!",
                            btn: ['确定'],
                            yes: function (index, layero) {
                                layer.close(index); //关闭当前弹窗
                                parent.layer.close(Indexs);
                            }
                        });
                    }
                } else {
                    // 如果请求失败
                    var msg = layer.open({
                        title: '提示',
                        content: data.message,
                        btn: ['确定'],
                        yes: function () {
                            layer.close(msg);  // 关闭当前弹窗
                            Feng.error("提交失败！");
                        }
                    });
                }
            },
            error: function(xhr, status, error) {
                // 请求出错时的回调函数
                parent.layer.close(index);
                layer.open({
                    title: '错误',
                    content: '请求失败，请稍后再试',
                    btn: ['确定'],
                    yes: function(index, layero){
                        layer.close(index); // 关闭当前弹窗
                    }
                });
                Feng.error("请求出错：" + error);
            }
        });
        return false;
    });

    //返回按钮
    $("#backupPage").click(function () {
        var Indexs = parent.layer.getFrameIndex(window.name);
        parent.layer.close(Indexs);
    });

});